import { defineAsyncComponent, h } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import type { MenuDataItem } from './typing';
import Layout from '@/layouts/index.vue';
// import UserLayout from '@/layouts/user-layout.vue';
import UserLayout2 from '@/layouts/user-layout2.vue';

export const routes: MenuDataItem[] = [
    {
        name: 'index',
        path: '/',
        redirect: '/list',
        component: Layout,
        children: [
            // {
            //     path: '/list',
            //     name: 'list',
            //     meta: { title: '基础数据', icon: 'TableOutlined' },
            //     component: RouteView,
            //     redirect: '/list/project-list',
            //     children: [
            //         {
            //             path: '/list/project-list',
            //             name: 'project-list',
            //             meta: { title: '项目管理' },
            //             component: (): Component => import(/* webpackChunkName: "list" */ '@/views/list/project-list/index.vue'),
            //         },
            //         {
            //             path: '/list/property-list',
            //             name: 'property-index',
            //             meta: { title: '房产管理' },
            //             component: (): Component => import(/* webpackChunkName: "list" */ '@/views/list/property-list/index.vue'),
            //         },
            //         {
            //             path: '/list/property-info',
            //             name: 'property-info',
            //             meta: { title: '房产管理详情', hideInMenu: true },
            //             component: (): Component => import(/* webpackChunkName: "list" */ '@/views/list/property-list/info.vue'),
            //         },
            //         {
            //             path: '/list/basic-list',
            //             name: 'basic-list',
            //             meta: { title: '员工管理' },
            //             component: (): Component => import(/* webpackChunkName: "list" */ '@/views/list/basic-list/index.vue'),
            //         },
            //         // {
            //         //     path: '/list/card-list',
            //         //     name: 'card-list',
            //         //     meta: { title: '客户关系' },
            //         //     component: (): Component => import(/* webpackChunkName: "list" */ '@/views/list/card-list/index.vue'),
            //         // },
            //     ],
            // },
            // {
            //     name: 'order',
            //     path: '/order',
            //     meta: { title: '工单管理', icon: 'FileSearchOutlined' },
            //     component: RouteView,
            //     redirect: '/order/center',
            //     children: [
            //         {
            //             name: 'mine-list',
            //             path: 'order/mine-list',
            //             // 由于 vuerouter 问题，三级路由开启 keepalive 会导致组件多次 setup
            //             meta: { title: '工单列表', keepAlive: false },
            //             component: () => import(/* webpackChunkName: "order" */ '@/views/order/mine/index.vue'),
            //             // 使用分割菜单时，你应该重定向到一个有权限的路由，避免 404
            //             redirect: '/order/order/mine-list/index',
            //             children: [
            //                 {
            //                     name: 'mine-list-index',
            //                     path: '/order/order/mine-list/index',
            //                     meta: { title: '我的工单' },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/mine/mine-list/index.vue'),
            //                 },
            //                 {
            //                     name: 'property-list',
            //                     path: '/order/property-list',
            //                     meta: { title: '地产工单', keepAlive: false },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/mine/property-list/index.vue'),
            //                 },
            //                 {
            //                     name: 'follow-up',
            //                     path: '/order/follow-up',
            //                     meta: { title: '回访工单', keepAlive: false },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/mine/follow-up/index.vue'),
            //                 },
            //                 {
            //                     name: 'praise-list',
            //                     path: '/order/praise-list',
            //                     meta: { title: '表扬工单', keepAlive: false },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/mine/praise-list/index.vue'),
            //                 },
            //             ],
            //         },
            //         {
            //             name: 'set-up',
            //             path: '/set-up',
            //             meta: {
            //                 title: '工单设置',
            //                 keepAlive: false,
            //             },
            //             redirect: '/order/set-up/cate',
            //             // component: () => import(/* webpackChunkName: "order" */ '@/views/examples/order/menu3.vue'),
            //             children: [
            //                 {
            //                     name: 'cate',
            //                     path: '/set-up/cate',
            //                     meta: { title: '工单分类' },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/set-up/cate/index.vue'),
            //                 },
            //                 {
            //                     name: 'flow',
            //                     path: '/set-up/flow',
            //                     meta: { title: '工单流程' },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/set-up/flow/index.vue'),
            //                 },
            //                 {
            //                     name: 'parameter',
            //                     path: '/set-up/parameter',
            //                     meta: { title: '参数配置' },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/set-up/parameter/index.vue'),
            //                 },
            //             ],
            //         },
            //         {
            //             name: 'analysis',
            //             path: '/analysis',
            //             meta: {
            //                 title: '统计分析',
            //                 keepAlive: false,
            //             },
            //             redirect: '/analysis/performance',
            //             children: [
            //                 {
            //                     name: 'performance',
            //                     path: '/analysis/performance',
            //                     meta: { title: '工单统计分析' },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/analysis/performance/index.vue'),
            //                 },
            //                 {
            //                     name: 'statistics',
            //                     path: '/analysis/statistics',
            //                     meta: { title: '工单绩效分析' },
            //                     component: () => import(/* webpackChunkName: "order" */ '@/views/order/analysis/statistics/index.vue'),
            //                 },
            //             ],
            //         },
            //     ],
            // },
            // {
            //     name: 'inspection',
            //     path: '/inspection',
            //     meta: { title: '巡检管理', icon: 'GatewayOutlined' },
            //     component: RouteView,
            //     redirect: '/inspection/quality',
            //     children: [
            //         {
            //             name: 'quality',
            //             path: '/inspection/quality',
            //             meta: { title: '品质巡检', keepAlive: false },
            //             redirect: 'inspection-plan',
            //             children: [
            //                 {
            //                     name: 'inspection-plan',
            //                     path: '/inspection-plan',
            //                     meta: { title: '巡检计划' },
            //                     component: () => import('@/views/inspection/quality/plan/index.vue'),
            //                 },
            //                 {
            //                     name: 'inspection-task',
            //                     path: '/inspection-task',
            //                     meta: { title: '巡检任务' },
            //                     component: () => import('@/views/inspection/quality/task/index.vue'),
            //                 },
            //                 {
            //                     name: 'inspection-temporaryTask',
            //                     path: '/inspection-temporaryTask',
            //                     meta: { title: '临时巡检任务' },
            //                     component: () => import('@/views/inspection/quality/temporaryTask/index.vue'),
            //                 },
            //                 {
            //                     name: 'inspection-order',
            //                     path: '/inspection-order',
            //                     meta: { title: '巡检工单' },
            //                     component: () => import('@/views/inspection/quality/order/index.vue'),
            //                 },
            //             ],
            //         },
            //         {
            //             name: 'set',
            //             path: '/set',
            //             meta: { title: '巡检设置', keepAlive: false },
            //             redirect: '/set/inspection-item',
            //             children: [
            //                 {
            //                     name: 'inspection-item',
            //                     path: 'inspection-item',
            //                     meta: { title: '检查事项设置' },
            //                     component: () => import('@/views/inspection/set/inspection-item/index.vue'),
            //                 },
            //                 {
            //                     name: 'inspection-position',
            //                     path: 'inspection-position',
            //                     meta: { title: '检查地点设置' },
            //                     component: () => import('@/views/inspection/set/inspection-position/index.vue'),
            //                 },
            //                 {
            //                     name: 'inspection-group',
            //                     path: 'inspection-group',
            //                     meta: { title: '巡检组管理' },
            //                     component: () => import('@/views/inspection/set/inspection-group/index.vue'),
            //                 },
            //             ],
            //         },
            //     ],
            // },
            // // system
            // {
            //     path: '/system',
            //     name: 'system',
            //     meta: { title: 'pages.system.title', icon: 'TableOutlined' },
            //     component: RouteView,
            //     redirect: '/system/role-list',
            //     children: [
            //         {
            //             path: '/project-relation',
            //             name: 'project-relation',
            //             meta: { title: '项目关联管理' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/project-relation.vue'),
            //         },
            //         {
            //             path: '/system/account-list',
            //             name: 'account-list',
            //             meta: { title: '用户管理' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/account-list.vue'),
            //         },
            //         {
            //             path: '/system/role-list',
            //             name: 'role-list',
            //             meta: { title: 'pages.system.role-list.title' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/role-list.vue'),
            //         },
            //         {
            //             path: '/system/permission-list',
            //             name: 'permission-list',
            //             meta: { title: 'pages.system.permission-list.title' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/permission-list.vue'),
            //         },
            //         {
            //             path: '/system/menu-list',
            //             name: 'menu-list',
            //             meta: { title: '菜单管理' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/menu-list.vue'),
            //         },
            //         {
            //             path: '/system/dict-list',
            //             name: 'dict-list',
            //             meta: { title: '字典管理' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/dict-list.vue'),
            //         },
            //         {
            //             path: '/system/login-log',
            //             name: 'login-log',
            //             meta: { title: '登录日志' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/logs-list/loginlog.vue'),
            //         },
            //         {
            //             path: '/system/operate-list',
            //             name: 'operate-list',
            //             meta: { title: '操作日志' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/logs-list/operatelog.vue'),
            //         },
            //         {
            //             path: '/system/app-list',
            //             name: 'app-list',
            //             meta: { title: 'APP版本控制' },
            //             component: (): Component => import(/* webpackChunkName: "system" */ '@/views/system/app-list.vue'),
            //         },
            //     ],
            // },
        ],
    },
];

export const staticRoutes: MenuDataItem[] = [
    {
        path: '/user',
        name: 'user',
        meta: { hideInMenu: true, title: 'pages.layouts.userLayout.title' },
        component: UserLayout2,
        children: [
            {
                path: '/user/login',
                name: 'login',
                meta: { title: 'pages.login.accountLogin.tab' },
                component: () => import(/* webpackChunkName: "user" */ '@/views/user/login.vue'),
            },
            {
                path: '/user/register',
                name: 'register',
                meta: { title: 'pages.login.registerAccount' },
                component: () => import(/* webpackChunkName: "user" */ '@/views/user/register.vue'),
            },
            {
                path: '/user/register-result',
                name: 'register-result',
                meta: { title: 'pages.login.registerAccount' },
                component: () => import(/* webpackChunkName: "user" */ '@/views/user/register-result.vue'),
            },
        ],
    },
    {
        path: '/:pathMatch(.*)',
        component: () => import(/* webpackChunkName: "exception" */ '@/views/exception/404.vue'),
    },
];

const router = createRouter({
    history: createWebHistory(process.env.VUE_APP_PUBLIC_PATH),
    routes: staticRoutes as RouteRecordRaw[],
    scrollBehavior: (to, from) => {
        if (to.path !== from.path) {
            setTimeout(() => {
                document.getElementById('app').scrollTop = 0;
            });
        }
        return { top: 0 };
    },
});

export default router;
